home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / unix / volume25 / ethertop < prev    next >
Encoding:
Internet Message Format  |  1991-12-13  |  39.2 KB

  1. Subject: v25i027: Monitor network utilization in terms of ``busiest hosts''
  2. Newsgroups: comp.sources.unix
  3. Approved: vixie@pa.dec.com
  4.  
  5. Submitted-By: Guy Cardwell <gcardwel@okazaki.acs.uci.edu>
  6. Posting-Number: Volume 25, Issue 27
  7. Archive-Name: ethertop
  8.  
  9. This utility displays the top N hosts in terms of how much they are using
  10. your ethernet.  This program depends on Sun's rpc.etherd, and uses curses.
  11.  
  12. #! /bin/sh
  13. # This is a shell archive.  Remove anything before this line, then unpack
  14. # it by saving it into a file and typing "sh file".  To overwrite existing
  15. # files, type "sh file -c".  You can also feed this as standard input via
  16. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  17. # will see the following message at the end:
  18. #        "End of archive 1 (of 1)."
  19. # Contents:  MANIFEST Makefile README buffer.c buffer.h copyright
  20. #   ethertop.c ethertop.h ethertop.man hostname.c patchlevel.h
  21. #   screen.c sort.c sort.h
  22. # Wrapped by vixie@cognition.pa.dec.com on Fri Dec 13 18:24:08 1991
  23. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  24. if test -f 'MANIFEST' -a "${1}" != "-c" ; then 
  25.   echo shar: Will not clobber existing file \"'MANIFEST'\"
  26. else
  27. echo shar: Extracting \"'MANIFEST'\" \(530 characters\)
  28. sed "s/^X//" >'MANIFEST' <<'END_OF_FILE'
  29. X   File Name        Archive #    Description
  30. X-----------------------------------------------------------
  31. X MANIFEST                   1    
  32. X Makefile                   1    
  33. X README                     1    
  34. X buffer.c                   1    
  35. X buffer.h                   1    
  36. X copyright                  1    
  37. X ethertop.c                 1    
  38. X ethertop.h                 1    
  39. X ethertop.man               1    
  40. X hostname.c                 1    
  41. X patchlevel.h               1    
  42. X screen.c                   1    
  43. X sort.c                     1    
  44. X sort.h                     1    
  45. END_OF_FILE
  46. if test 530 -ne `wc -c <'MANIFEST'`; then
  47.     echo shar: \"'MANIFEST'\" unpacked with wrong size!
  48. fi
  49. # end of 'MANIFEST'
  50. fi
  51. if test -f 'Makefile' -a "${1}" != "-c" ; then 
  52.   echo shar: Will not clobber existing file \"'Makefile'\"
  53. else
  54. echo shar: Extracting \"'Makefile'\" \(5807 characters\)
  55. sed "s/^X//" >'Makefile' <<'END_OF_FILE'
  56. BINDIR=/usr/local/bin
  57. MANDIR=/usr/man/manl
  58. MANEXT=l
  59. CC=cc -O
  60. X
  61. all: ethertop
  62. X
  63. ethertop: ethertop.o sort.o buffer.o hostname.o ether_clnt.o ether_xdr.o 
  64. X    $(CC) -o ethertop ethertop.o sort.o buffer.o hostname.o ether_clnt.o ether_xdr.o -lcurses -ltermcap -lm
  65. X
  66. depend: ether.h
  67. X    makedepend *.c *.h
  68. X
  69. clean:
  70. X    rm -f *.o *~ ethertop TAGS ether.h ether_clnt.c ether_svc.c ether_xdr.c ether.x
  71. X
  72. dist: README Makefile copyright buffer.c ethertop.c hostname.c screen.c sort.h buffer.h ethertop.h patchlevel.h sort.c ethertop.man
  73. X    shar README Makefile copyright buffer.c ethertop.c hostname.c screen.c sort.h buffer.h ethertop.h patchlevel.h sort.c ethertop.man >ethertop.shar
  74. X
  75. ether.h: /usr/include/rpcsvc/ether.x
  76. X    cp /usr/include/rpcsvc/ether.x .
  77. X    rpcgen ether.x
  78. X
  79. install: ethertop
  80. X    install -c -m 755 ethertop $(BINDIR)
  81. X
  82. install.man: ethertop.man
  83. X    install -c -m 644 ethertop.man $(MANDIR)/ethertop.$(MANEXT)
  84. X
  85. X# DO NOT DELETE THIS LINE -- make depend depends on it.
  86. X
  87. buffer.o: buffer.h /usr/include/stdio.h
  88. ether_clnt.o: /usr/include/rpc/rpc.h /usr/include/rpc/types.h
  89. ether_clnt.o: /usr/include/malloc.h /usr/include/sys/types.h
  90. ether_clnt.o: /usr/include/sys/stdtypes.h /usr/include/sys/sysmacros.h
  91. ether_clnt.o: /usr/include/sys/time.h /usr/include/sys/time.h
  92. ether_clnt.o: /usr/include/netinet/in.h /usr/include/rpc/xdr.h
  93. ether_clnt.o: /usr/include/rpc/auth.h /usr/include/rpc/clnt.h
  94. ether_clnt.o: /usr/include/rpc/rpc_msg.h /usr/include/rpc/auth_unix.h
  95. ether_clnt.o: /usr/include/rpc/auth_des.h /usr/include/rpc/svc.h
  96. ether_clnt.o: /usr/include/rpc/svc_auth.h ether.h
  97. ether_svc.o: /usr/include/stdio.h /usr/include/rpc/rpc.h
  98. ether_svc.o: /usr/include/rpc/types.h /usr/include/malloc.h
  99. ether_svc.o: /usr/include/sys/types.h /usr/include/sys/stdtypes.h
  100. ether_svc.o: /usr/include/sys/sysmacros.h /usr/include/sys/time.h
  101. ether_svc.o: /usr/include/sys/time.h /usr/include/netinet/in.h
  102. ether_svc.o: /usr/include/rpc/xdr.h /usr/include/rpc/auth.h
  103. ether_svc.o: /usr/include/rpc/clnt.h /usr/include/rpc/rpc_msg.h
  104. ether_svc.o: /usr/include/rpc/auth_unix.h /usr/include/rpc/auth_des.h
  105. ether_svc.o: /usr/include/rpc/svc.h /usr/include/rpc/svc_auth.h ether.h
  106. ether_xdr.o: /usr/include/rpc/rpc.h /usr/include/rpc/types.h
  107. ether_xdr.o: /usr/include/malloc.h /usr/include/sys/types.h
  108. ether_xdr.o: /usr/include/sys/stdtypes.h /usr/include/sys/sysmacros.h
  109. ether_xdr.o: /usr/include/sys/time.h /usr/include/sys/time.h
  110. ether_xdr.o: /usr/include/netinet/in.h /usr/include/rpc/xdr.h
  111. ether_xdr.o: /usr/include/rpc/auth.h /usr/include/rpc/clnt.h
  112. ether_xdr.o: /usr/include/rpc/rpc_msg.h /usr/include/rpc/auth_unix.h
  113. ether_xdr.o: /usr/include/rpc/auth_des.h /usr/include/rpc/svc.h
  114. ether_xdr.o: /usr/include/rpc/svc_auth.h ether.h
  115. ethertop.o: /usr/include/stdio.h /usr/include/curses.h /usr/include/sgtty.h
  116. ethertop.o: /usr/include/sys/ioctl.h /usr/include/sys/ttychars.h
  117. ethertop.o: /usr/include/sys/ttydev.h /usr/include/sys/ttold.h
  118. ethertop.o: /usr/include/sys/ioccom.h /usr/include/sys/ttycom.h
  119. ethertop.o: /usr/include/sys/filio.h /usr/include/sys/sockio.h
  120. ethertop.o: /usr/include/signal.h /usr/include/sys/signal.h
  121. ethertop.o: /usr/include/vm/faultcode.h /usr/include/ctype.h
  122. ethertop.o: /usr/include/sys/types.h /usr/include/sys/stdtypes.h
  123. ethertop.o: /usr/include/sys/sysmacros.h /usr/include/sys/time.h
  124. ethertop.o: /usr/include/sys/time.h /usr/include/math.h
  125. ethertop.o: /usr/include/floatingpoint.h /usr/include/sys/ieeefp.h ethertop.h
  126. ethertop.o: /usr/include/rpc/rpc.h /usr/include/rpc/types.h
  127. ethertop.o: /usr/include/malloc.h /usr/include/netinet/in.h
  128. ethertop.o: /usr/include/rpc/xdr.h /usr/include/rpc/auth.h
  129. ethertop.o: /usr/include/rpc/clnt.h /usr/include/rpc/rpc_msg.h
  130. ethertop.o: /usr/include/rpc/auth_unix.h /usr/include/rpc/auth_des.h
  131. ethertop.o: /usr/include/rpc/svc.h /usr/include/rpc/svc_auth.h ether.h
  132. ethertop.o: buffer.h sort.h
  133. hostname.o: /usr/include/stdio.h /usr/include/sys/types.h
  134. hostname.o: /usr/include/sys/stdtypes.h /usr/include/sys/sysmacros.h
  135. hostname.o: /usr/include/sys/socket.h /usr/include/netdb.h
  136. hostname.o: /usr/include/string.h ethertop.h /usr/include/rpc/rpc.h
  137. hostname.o: /usr/include/rpc/types.h /usr/include/malloc.h
  138. hostname.o: /usr/include/sys/time.h /usr/include/sys/time.h
  139. hostname.o: /usr/include/netinet/in.h /usr/include/rpc/xdr.h
  140. hostname.o: /usr/include/rpc/auth.h /usr/include/rpc/clnt.h
  141. hostname.o: /usr/include/rpc/rpc_msg.h /usr/include/rpc/auth_unix.h
  142. hostname.o: /usr/include/rpc/auth_des.h /usr/include/rpc/svc.h
  143. hostname.o: /usr/include/rpc/svc_auth.h ether.h
  144. sort.o: /usr/include/stdio.h ethertop.h /usr/include/rpc/rpc.h
  145. sort.o: /usr/include/rpc/types.h /usr/include/malloc.h
  146. sort.o: /usr/include/sys/types.h /usr/include/sys/stdtypes.h
  147. sort.o: /usr/include/sys/sysmacros.h /usr/include/sys/time.h
  148. sort.o: /usr/include/sys/time.h /usr/include/netinet/in.h
  149. sort.o: /usr/include/rpc/xdr.h /usr/include/rpc/auth.h
  150. sort.o: /usr/include/rpc/clnt.h /usr/include/rpc/rpc_msg.h
  151. sort.o: /usr/include/rpc/auth_unix.h /usr/include/rpc/auth_des.h
  152. sort.o: /usr/include/rpc/svc.h /usr/include/rpc/svc_auth.h ether.h buffer.h
  153. ether.o: /usr/include/rpc/types.h /usr/include/malloc.h
  154. ether.o: /usr/include/sys/types.h /usr/include/sys/stdtypes.h
  155. ether.o: /usr/include/sys/sysmacros.h /usr/include/sys/time.h
  156. ether.o: /usr/include/sys/time.h
  157. ethertop.o: /usr/include/rpc/rpc.h /usr/include/rpc/types.h
  158. ethertop.o: /usr/include/malloc.h /usr/include/sys/types.h
  159. ethertop.o: /usr/include/sys/stdtypes.h /usr/include/sys/sysmacros.h
  160. ethertop.o: /usr/include/sys/time.h /usr/include/sys/time.h
  161. ethertop.o: /usr/include/netinet/in.h /usr/include/rpc/xdr.h
  162. ethertop.o: /usr/include/rpc/auth.h /usr/include/rpc/clnt.h
  163. ethertop.o: /usr/include/rpc/rpc_msg.h /usr/include/rpc/auth_unix.h
  164. ethertop.o: /usr/include/rpc/auth_des.h /usr/include/rpc/svc.h
  165. ethertop.o: /usr/include/rpc/svc_auth.h ether.h
  166. END_OF_FILE
  167. if test 5807 -ne `wc -c <'Makefile'`; then
  168.     echo shar: \"'Makefile'\" unpacked with wrong size!
  169. fi
  170. # end of 'Makefile'
  171. fi
  172. if test -f 'README' -a "${1}" != "-c" ; then 
  173.   echo shar: Will not clobber existing file \"'README'\"
  174. else
  175. echo shar: Extracting \"'README'\" \(553 characters\)
  176. sed "s/^X//" >'README' <<'END_OF_FILE'
  177. Installing ethertop is easy.
  178. X
  179. There is an install target and an install.man target.  Adjust
  180. the directory locations in the Makefile for your binaries
  181. directory, you man pages directories, and the manual page
  182. extension you use. Then type make and make install.  make clean
  183. cleans up the mess.
  184. X
  185. There is a little hangup with dependences with the rpcgen.  If you
  186. delete the rpcgen generated code, you may have to type make twice.
  187. X
  188. If you are building under something other than SunOS 4.1.1, you may
  189. want to run make depend.
  190. X
  191. X
  192. Guy Cardwell
  193. gcardwel@uci.edu
  194. END_OF_FILE
  195. if test 553 -ne `wc -c <'README'`; then
  196.     echo shar: \"'README'\" unpacked with wrong size!
  197. fi
  198. # end of 'README'
  199. fi
  200. if test -f 'buffer.c' -a "${1}" != "-c" ; then 
  201.   echo shar: Will not clobber existing file \"'buffer.c'\"
  202. else
  203. echo shar: Extracting \"'buffer.c'\" \(1472 characters\)
  204. sed "s/^X//" >'buffer.c' <<'END_OF_FILE'
  205. X/*
  206. X * Copyright (c) 1991 Regents of the University of California.
  207. X * All rights reserved.
  208. X *
  209. X * Redistribution and use in source and binary forms are permitted
  210. X * provided that the above copyright notice and this paragraph are
  211. X * duplicated in all such forms and that any documentation,
  212. X * advertising materials, and other materials related to such
  213. X * distribution and use acknowledge that the software was developed
  214. X * by the University of California, Irvine.  The name of the
  215. X * University may not be used to endorse or promote products derived
  216. X * from this software without specific prior written permission.
  217. X * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  218. X * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  219. X * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  220. X */
  221. X#include "buffer.h"
  222. X#include <stdio.h>
  223. X
  224. void add_buffer(buf, entry)
  225. buffer *buf;
  226. void *entry;
  227. X{
  228. X  buf->p[buf->end]=entry;
  229. X  buf->end++;
  230. X  if (buf->end == buf->len)
  231. X    {
  232. X      fprintf(stderr,"reallocing buffer\n");
  233. X      buf->len+=BUFLEN;
  234. X      buf->p=(void **)realloc(buf->p,buf->len);
  235. X    }
  236. X}
  237. X
  238. void clear_buffer(buf)
  239. buffer *buf;
  240. X{
  241. buf->end=0;
  242. X}
  243. X
  244. void free_buffer(buf)
  245. buffer *buf;
  246. X{
  247. unsigned int i;
  248. for (i=0; i<buf->end; i++)
  249. X    free(buf->p[i]);
  250. buf->end=0;
  251. X}
  252. X
  253. X
  254. buffer *init_buffer()
  255. X{
  256. X  buffer *buf;
  257. X  
  258. X  buf= (buffer *) malloc (sizeof(buffer));
  259. X  buf->p=(void **) malloc(BUFLEN*sizeof(void *));
  260. X  buf->end=0;
  261. X  buf->len=BUFLEN;
  262. X  return (buf);
  263. X}
  264. X
  265. X
  266. X
  267. X
  268. END_OF_FILE
  269. if test 1472 -ne `wc -c <'buffer.c'`; then
  270.     echo shar: \"'buffer.c'\" unpacked with wrong size!
  271. fi
  272. # end of 'buffer.c'
  273. fi
  274. if test -f 'buffer.h' -a "${1}" != "-c" ; then 
  275.   echo shar: Will not clobber existing file \"'buffer.h'\"
  276. else
  277. echo shar: Extracting \"'buffer.h'\" \(1013 characters\)
  278. sed "s/^X//" >'buffer.h' <<'END_OF_FILE'
  279. X/*
  280. X * Copyright (c) 1991 Regents of the University of California.
  281. X * All rights reserved.
  282. X *
  283. X * Redistribution and use in source and binary forms are permitted
  284. X * provided that the above copyright notice and this paragraph are
  285. X * duplicated in all such forms and that any documentation,
  286. X * advertising materials, and other materials related to such
  287. X * distribution and use acknowledge that the software was developed
  288. X * by the University of California, Irvine.  The name of the
  289. X * University may not be used to endorse or promote products derived
  290. X * from this software without specific prior written permission.
  291. X * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  292. X * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  293. X * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  294. X */
  295. X#define BUFLEN 1024
  296. X
  297. X
  298. typedef struct {
  299. X    void **p;
  300. X    unsigned int end;
  301. X    unsigned int len;
  302. X  } buffer;
  303. X
  304. X
  305. void add_buffer();
  306. buffer *init_buffer();
  307. void clear_buffer();
  308. void free_buffer();
  309. END_OF_FILE
  310. if test 1013 -ne `wc -c <'buffer.h'`; then
  311.     echo shar: \"'buffer.h'\" unpacked with wrong size!
  312. fi
  313. # end of 'buffer.h'
  314. fi
  315. if test -f 'copyright' -a "${1}" != "-c" ; then 
  316.   echo shar: Will not clobber existing file \"'copyright'\"
  317. else
  318. echo shar: Extracting \"'copyright'\" \(819 characters\)
  319. sed "s/^X//" >'copyright' <<'END_OF_FILE'
  320. X/*
  321. X * Copyright (c) 1991 Regents of the University of California.
  322. X * All rights reserved.
  323. X *
  324. X * Redistribution and use in source and binary forms are permitted
  325. X * provided that the above copyright notice and this paragraph are
  326. X * duplicated in all such forms and that any documentation,
  327. X * advertising materials, and other materials related to such
  328. X * distribution and use acknowledge that the software was developed
  329. X * by the University of California, Irvine.  The name of the
  330. X * University may not be used to endorse or promote products derived
  331. X * from this software without specific prior written permission.
  332. X * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  333. X * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  334. X * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  335. X */
  336. END_OF_FILE
  337. if test 819 -ne `wc -c <'copyright'`; then
  338.     echo shar: \"'copyright'\" unpacked with wrong size!
  339. fi
  340. # end of 'copyright'
  341. fi
  342. if test -f 'ethertop.c' -a "${1}" != "-c" ; then 
  343.   echo shar: Will not clobber existing file \"'ethertop.c'\"
  344. else
  345. echo shar: Extracting \"'ethertop.c'\" \(10135 characters\)
  346. sed "s/^X//" >'ethertop.c' <<'END_OF_FILE'
  347. X/*
  348. X * Copyright (c) 1991 Regents of the University of California.
  349. X * All rights reserved.
  350. X *
  351. X * Redistribution and use in source and binary forms are permitted
  352. X * provided that the above copyright notice and this paragraph are
  353. X * duplicated in all such forms and that any documentation,
  354. X * advertising materials, and other materials related to such
  355. X * distribution and use acknowledge that the software was developed
  356. X * by the University of California, Irvine.  The name of the
  357. X * University may not be used to endorse or promote products derived
  358. X * from this software without specific prior written permission.
  359. X * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  360. X * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  361. X * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  362. X */
  363. X#include <stdio.h>
  364. X#include <curses.h>
  365. X#include <signal.h>
  366. X#include <ctype.h>
  367. X#include <sys/types.h>
  368. X#include <sys/time.h>
  369. X#include <math.h>
  370. X#include "ethertop.h"
  371. X#include "buffer.h"
  372. X#include "sort.h"
  373. X#ifndef lint
  374. char copyright[]="Copyright (c) 1991 Regents of the University of California. All rights reserved.";
  375. X#endif 
  376. WINDOW *src_window;
  377. WINDOW *dest_window;
  378. WINDOW *size_window1;
  379. WINDOW *size_window2;
  380. WINDOW *load_window;
  381. WINDOW *user_window;
  382. X
  383. struct sgttyb tty_settings;
  384. X
  385. displayip=FALSE;
  386. total=FALSE;
  387. char *server;
  388. int maxlines;
  389. X
  390. void swan_song(message)
  391. char *message;
  392. X{
  393. X  clear();
  394. X  mvcur(0, COLS-1, LINES-1, 0);
  395. X  refresh();
  396. X  endwin();
  397. X  perror(message);
  398. X  fflush(stderr);
  399. X  exit(0);
  400. X}
  401. X
  402. void death()
  403. X{
  404. X  signal(SIGINT, SIG_IGN);
  405. X  clear();
  406. X  mvcur(0, COLS-1, LINES-1, 0);
  407. X  refresh();
  408. X  endwin();
  409. X  exit(0);
  410. X}
  411. X
  412. X/*
  413. X         1         2         3         4         5         6         7         
  414. X1234567890123456789012345678901234567890123456789012345678901234567890123456789
  415. X*/
  416. X/*
  417. X       |       |       |       |       |       |       |       |       |
  418. X*/
  419. X
  420. X
  421. void setup_screen()
  422. X{
  423. X  int x;
  424. X  signal(SIGINT, death);
  425. X  ioctl(0,TIOCGETP,&tty_settings);
  426. X  initscr();
  427. X  maxlines=LINES-9;
  428. X  noecho();
  429. X  crmode();
  430. X  nonl();
  431. X  user_window=newwin(1,0,0,0);
  432. X  scrollok(stdscr,0);
  433. X  load_window=subwin(stdscr,1,0,2,0);
  434. X  size_window1=subwin(stdscr,1,0,5,0);
  435. X  size_window2=subwin(stdscr,1,0,7,0);
  436. X  src_window=subwin(stdscr,LINES-10,39,10,0);
  437. X  dest_window=subwin(stdscr,LINES-10,39,10,41);
  438. X  move(0,0);
  439. X  printw("Network load as seen from %s", server);
  440. X  move(1,0);
  441. X  printw("   bytes    pkts    bcst     tcp     udp    icmp     arp      nd     oth");
  442. X  move(3,0);
  443. X  printw("packet sizes:");
  444. X  move(4,0);
  445. X  printw(" 64-154  155-245    246-336    337-427   428-518   519-609   610-699   700-790");
  446. X  move(6,0);
  447. X  printw("791-881  882-972   973-1063  1064-1154 1155-1245 1246-1336 1337-1427 1428-1518");
  448. X  move(8,0);
  449. X  printw("--------------------------------------------------------------------------------");
  450. X  move(9,0);
  451. X  printw("HOSTNAME                          SENT | HOSTNAME                          RECV ");
  452. X  for (x=9; x!=LINES; x++)
  453. X    {
  454. X      move(x,39);
  455. X      addch('|');
  456. X    }
  457. X}
  458. X
  459. void display_data(diffstat)
  460. etherfloatstat *diffstat;
  461. X{
  462. X      
  463. X      wmove(load_window,0,0);
  464. X      wprintw(load_window,"%7.2fK %7.2f %7.2f %7.2f %7.2f %7.2f %7.2f %7.2f %7.2f",
  465. X          (double) diffstat->e_bytes/1024.0,
  466. X          (double) diffstat->e_packets,
  467. X          (double) diffstat->e_bcast,
  468. X          (double) diffstat->e_proto[3], 
  469. X          (double) diffstat->e_proto[2],
  470. X          (double) diffstat->e_proto[1],
  471. X          (double) diffstat->e_proto[4],
  472. X          (double) diffstat->e_proto[0],
  473. X          (double) diffstat->e_proto[5]);
  474. X      
  475. X      wmove(size_window1,0,0);
  476. X      wprintw(size_window1,"%7.2f  %7.2f    %7.2f    %7.2f   %7.2f   %7.2f   %7.2f   %7.2f ",
  477. X          (double) diffstat->e_size[0],
  478. X          (double) diffstat->e_size[1],
  479. X          (double) diffstat->e_size[2],
  480. X          (double) diffstat->e_size[3],
  481. X          (double) diffstat->e_size[4],
  482. X          (double) diffstat->e_size[5],
  483. X          (double) diffstat->e_size[6],
  484. X          (double) diffstat->e_size[7]);
  485. X
  486. X      wmove(size_window2,0,0);
  487. X      wprintw(size_window2,"%7.2f  %7.2f    %7.2f    %7.2f   %7.2f   %7.2f   %7.2f   %7.2f ",
  488. X          (double) diffstat->e_size[8],
  489. X          (double) diffstat->e_size[9],
  490. X          (double) diffstat->e_size[10],
  491. X          (double) diffstat->e_size[11],
  492. X          (double) diffstat->e_size[12],
  493. X          (double) diffstat->e_size[13],
  494. X          (double) diffstat->e_size[14],
  495. X          (double) diffstat->e_size[15]);
  496. X
  497. X}
  498. X
  499. void display_a_list(window,buf)
  500. X     WINDOW *window;
  501. X     buffer *buf;
  502. X{
  503. X  register unsigned int i;
  504. X  etherfloat_node *ptr;
  505. X  for (i=0; i<maxlines && i<buf->end; i++)
  506. X    {
  507. X      wmove(window,i,0);
  508. X      ptr=buf->p[i];
  509. X      wprintw(window, "%-30.30s %7.2f", 
  510. X          gethostnamebyip(ptr->h_addr),
  511. X          (double)ptr->h_cnt);
  512. X    }
  513. X  wmove(window,i,0);
  514. X  wclrtobot(window);
  515. X}
  516. X
  517. X/* I am not proud of this routine, but it works */
  518. int wgnum(window,min,max)
  519. WINDOW *window;
  520. int min;
  521. int max;
  522. X{
  523. X  int ch;
  524. X  int i=0;
  525. X  int x,y;
  526. X  int maxchar;
  527. X  int minchar;
  528. X  char string[80];
  529. X  bzero(string,80);
  530. X  maxchar=(int) log10 ((double) (max*10));
  531. X  nl();
  532. X  noecho();
  533. X  getyx(window,y,x);
  534. X  while(1)
  535. X    {
  536. X      ch=getch();
  537. X      if ((ch=='\n')
  538. X      && i>0
  539. X      && (atoi(string) <=max)
  540. X      && (atoi(string) >= min) )
  541. X    {
  542. X      nonl();
  543. X      noecho();
  544. X      return(atoi(string));
  545. X    }
  546. X      if(ch==tty_settings.sg_erase)
  547. X    {
  548. X      if(i>0)
  549. X        {
  550. X          string[--i]=0;
  551. X          mvwdelch(window,y,x+i);
  552. X          wrefresh(window);
  553. X          continue;
  554. X        }
  555. X      else
  556. X        {
  557. X          continue;
  558. X        }
  559. X    }
  560. X      if(isdigit(ch))
  561. X    {
  562. X      if (i<maxchar)
  563. X        {
  564. X          string[i++]=ch;
  565. X          mvwaddch(window,y,x+i-1,ch);
  566. X          wrefresh(window);
  567. X          continue;
  568. X        }
  569. X    }
  570. X    }
  571. X}
  572. X
  573. X
  574. void process_input()
  575. X{
  576. X  switch(tolower(getch()))
  577. X    {
  578. X    case 'i':
  579. X      displayip=!displayip;
  580. X      break;
  581. X    case 't':
  582. X      total=!total;
  583. X      break;
  584. X    case 'q':
  585. X      death();
  586. X      break;
  587. X    case 'l':
  588. X      wrefresh(curscr);
  589. X      break;
  590. X    case 's':
  591. X      {
  592. X    werase(user_window);
  593. X    wstandout(user_window);
  594. X    waddstr(user_window,"Seconds to delay:");
  595. X    wstandend(user_window);
  596. X    waddstr(user_window," ");
  597. X    touchwin(user_window);
  598. X    wrefresh(user_window);
  599. X    timeout.tv_sec=wgnum(user_window,2,3600);
  600. X    touchwin(stdscr);
  601. X    refresh();
  602. X    break;
  603. X      }
  604. X    case 'n':
  605. X          werase(user_window);
  606. X    wstandout(user_window);
  607. X    waddstr(user_window,"Hosts to display:");
  608. X    wstandend(user_window);
  609. X    waddstr(user_window," ");
  610. X    touchwin(user_window);
  611. X    wrefresh(user_window);
  612. X    maxlines=wgnum(user_window,0,LINES-9);
  613. X    touchwin(stdscr);
  614. X    refresh();
  615. X    break;
  616. X    default:
  617. X      ;
  618. X    }
  619. X}
  620. X
  621. X
  622. int errflg=0;
  623. etherfloatstat diffstat;
  624. etheraddrs old_src_addrs;
  625. etheraddrs old_dest_addrs; 
  626. etherstat old_stat_data;
  627. fd_set readfds,tempreadfds;
  628. struct timeval timeout={5,0};
  629. struct timeval temptimeout;
  630. extern char *optarg;
  631. extern int optind, opterr;
  632. X      
  633. X
  634. main(argc, argv)
  635. X
  636. X     char *argv[];
  637. X{
  638. X  CLIENT *cl;
  639. X  etherstat *stat_data;
  640. X  etheraddrs *src_addrs;
  641. X  etheraddrs *dest_addrs;
  642. X  buffer *src_buf;
  643. X  buffer *dest_buf;
  644. X  char c;
  645. X
  646. X  while ((c=getopt(argc, argv, "is:t"))!=-1)
  647. X    switch(c)
  648. X      {
  649. X      case 'i':
  650. X    displayip++;
  651. X    break;
  652. X    
  653. X      case 's':
  654. X    timeout.tv_sec=atol(optarg);
  655. X    if (timeout.tv_sec<2)
  656. X      errflg++;
  657. X    break;
  658. X    
  659. X      case 't':
  660. X    total++;
  661. X    break;
  662. X
  663. X      case '?':
  664. X    errflg++;
  665. X    break;
  666. X      }
  667. X
  668. X  if (optind!=argc-1  || errflg)
  669. X    {
  670. X      fprintf(stderr,"Usage:\n");
  671. X      fprintf(stderr,"%s [options] hostname\n\n",argv[0]);
  672. X      fprintf(stderr,"options are:\n");
  673. X      fprintf(stderr,"-i           don't map ip numbers to hostnames\n");
  674. X      fprintf(stderr,"-s int       seconds between updates.  Minimum of 2 seconds.\n");
  675. X      fprintf(stderr,"-t           display time averaged totals, rather than instantanous averages\n");
  676. X      exit(2);
  677. X    }
  678. X  server=argv[optind];
  679. X
  680. X  src_buf=init_buffer();     
  681. X  dest_buf=init_buffer();
  682. X  cl = clnt_create(server, ETHERPROG, ETHERVERS, "udp");
  683. X  if (cl == NULL)
  684. X    {
  685. X      clnt_pcreateerror(server);
  686. X      exit(1);
  687. X    }
  688. X  setup_screen();
  689. X  init_gethostnamebyip();
  690. X  FD_ZERO(&readfds);
  691. X  FD_SET(0,&readfds); /* set up stdin for select */
  692. X  
  693. X
  694. X  if((etherproc_on_1((void *)NULL,cl))==NULL)
  695. X    swan_song("etherproc_on failed. rpc.etherd probably died");
  696. X
  697. X  if((stat_data=etherproc_getdata_1((void *) NULL, cl))==NULL)
  698. X    swan_song("etherproc_getdata failed. rpc.etherd probably died");
  699. X     
  700. X  old_stat_data=*stat_data;
  701. X  
  702. X  if((src_addrs=etherproc_getsrcdata_1((void *) NULL, cl))==NULL)
  703. X    swan_song("etherproc_getdata failed. rpc.etherd probably died");
  704. X
  705. X  old_src_addrs=*src_addrs;
  706. X
  707. X  if( (dest_addrs =etherproc_getdstdata_1((void *) NULL, cl))==NULL)
  708. X    swan_song("etherproc_getdata failed. rpc.etherd probably died");
  709. X
  710. X
  711. X  old_dest_addrs=*dest_addrs;
  712. X  sleep(1); /*snewz*/
  713. X  
  714. X  for (;;)
  715. X    {
  716. X      move(2,0);
  717. X      refresh();
  718. X      tempreadfds=readfds;
  719. X      temptimeout=timeout;
  720. X      if(select(3,&tempreadfds,NULL,NULL,&temptimeout))
  721. X    process_input();
  722. X
  723. X      if( (stat_data=etherproc_getdata_1((void *) NULL, cl))==NULL)
  724. X    swan_song("etherproc_getdata failed. rpc.etherd probably died");
  725. X
  726. X      subtract_etherstat(stat_data,&old_stat_data,&diffstat);
  727. X      if (total)
  728. X    {
  729. X      xdr_free(xdr_etherstat,stat_data);
  730. X    }
  731. X      else
  732. X    {
  733. X      xdr_free(xdr_etherstat,&old_stat_data);
  734. X      old_stat_data=*stat_data;
  735. X    }
  736. X      
  737. X      display_data(&diffstat);
  738. X      
  739. X      if( (src_addrs =etherproc_getsrcdata_1((void *) NULL, cl))==NULL)
  740. X    swan_song("etherproc_getsrcdata failed. rpc.etherd probably died");
  741. X
  742. X      subtract_and_sort_etheraddrs(src_addrs, &old_src_addrs, src_buf);
  743. X
  744. X      if (total)
  745. X    {
  746. X      xdr_free(xdr_etheraddrs,src_addrs);
  747. X    }
  748. X      else
  749. X    {
  750. X      xdr_free(xdr_etheraddrs,&old_src_addrs);
  751. X      old_src_addrs=*src_addrs;
  752. X    }
  753. X
  754. X      
  755. X      if( (dest_addrs=etherproc_getdstdata_1((void *) NULL, cl))==NULL)
  756. X    swan_song("etherproc_getdstdata failed. rpc.etherd probably died");
  757. X
  758. X      subtract_and_sort_etheraddrs(dest_addrs, &old_dest_addrs, dest_buf);
  759. X      if (total)
  760. X    {
  761. X      xdr_free(xdr_etheraddrs,dest_addrs);
  762. X    }
  763. X      else
  764. X    {
  765. X      xdr_free(xdr_etheraddrs,&old_dest_addrs);
  766. X      old_dest_addrs=*dest_addrs;
  767. X    }
  768. X      display_a_list(src_window,src_buf);
  769. X      display_a_list(dest_window,dest_buf);
  770. X      free_buffer(src_buf);
  771. X      free_buffer(dest_buf);
  772. X    }
  773. X}
  774. X
  775. X
  776. X
  777. X
  778. X
  779. X
  780. X      
  781. X
  782. X
  783. X
  784. X
  785. X
  786. X
  787. END_OF_FILE
  788. if test 10135 -ne `wc -c <'ethertop.c'`; then
  789.     echo shar: \"'ethertop.c'\" unpacked with wrong size!
  790. fi
  791. # end of 'ethertop.c'
  792. fi
  793. if test -f 'ethertop.h' -a "${1}" != "-c" ; then 
  794.   echo shar: Will not clobber existing file \"'ethertop.h'\"
  795. else
  796. echo shar: Extracting \"'ethertop.h'\" \(1517 characters\)
  797. sed "s/^X//" >'ethertop.h' <<'END_OF_FILE'
  798. X/*
  799. X * Copyright (c) 1991 Regents of the University of California.
  800. X * All rights reserved.
  801. X *
  802. X * Redistribution and use in source and binary forms are permitted
  803. X * provided that the above copyright notice and this paragraph are
  804. X * duplicated in all such forms and that any documentation,
  805. X * advertising materials, and other materials related to such
  806. X * distribution and use acknowledge that the software was developed
  807. X * by the University of California, Irvine.  The name of the
  808. X * University may not be used to endorse or promote products derived
  809. X * from this software without specific prior written permission.
  810. X * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  811. X * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  812. X * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  813. X */
  814. X#include <rpc/rpc.h>
  815. X#undef h_addr
  816. X#include "ether.h"
  817. X
  818. X
  819. struct etherfloat_node {
  820. X    int h_addr;
  821. X    float h_cnt;
  822. X};
  823. typedef struct etherfloat_node etherfloat_node;
  824. extern displayip;
  825. extern char *server;
  826. extern struct timeval timeout;
  827. extern total;
  828. char *inet_ntoa();
  829. char *gethostnamebyip();
  830. void init_gethostnamebyip();
  831. struct host_ip_ent
  832. X{
  833. X  int h_addr;
  834. X  char *h_name;
  835. X  struct host_ip_ent *h_nxt;
  836. X};
  837. X
  838. typedef struct host_ip_ent host_ip_ent;
  839. X#define H2IP_HASH_SIZE 0x2000
  840. X#define H2IP_HASH_MASK 0x1FFF
  841. X
  842. struct etherfloatstat {
  843. X    float e_time;
  844. X    float e_bytes;
  845. X    float e_packets;
  846. X    float e_bcast;
  847. X    float e_size[NBUCKETS];
  848. X    float e_proto[NPROTOS];
  849. X};
  850. typedef struct etherfloatstat etherfloatstat;
  851. X
  852. X
  853. X
  854. X
  855. X
  856. X
  857. X
  858. X
  859. X
  860. END_OF_FILE
  861. if test 1517 -ne `wc -c <'ethertop.h'`; then
  862.     echo shar: \"'ethertop.h'\" unpacked with wrong size!
  863. fi
  864. # end of 'ethertop.h'
  865. fi
  866. if test -f 'ethertop.man' -a "${1}" != "-c" ; then 
  867.   echo shar: Will not clobber existing file \"'ethertop.man'\"
  868. else
  869. echo shar: Extracting \"'ethertop.man'\" \(4091 characters\)
  870. sed "s/^X//" >'ethertop.man' <<'END_OF_FILE'
  871. X.TH ethertop 1 "11/26/1991"
  872. X.SH NAME
  873. X.B ethertop
  874. X\- display and update information about the top network using machines
  875. X.SH SYNOPSIS
  876. X.B ethertop
  877. X.B [
  878. X-it
  879. X.B ]
  880. X.B [
  881. X-s seconds
  882. X.B ]
  883. hostname
  884. X.SH DESCRIPTION
  885. X.B ethertop
  886. is a program which displays network usage in the form of
  887. top(1).  
  888. X.B ethertop
  889. uses the rpc.etherd(8) server running on the host
  890. specified host to gather information about the network.  traffic(1)
  891. provides a visual display of this using Sunview.  
  892. X.B ethertop
  893. is
  894. purely text based, although an X version is in the works.  
  895. X.B ethertop
  896. is
  897. intended for quick diagnosis of network problems.  Questions like "who
  898. is beating on the fileserver" are very quickly answered by a glance at
  899. the 
  900. X.B ethertop
  901. statistics.  Note that rpc.etherd must be running on a 
  902. machine on the network you are interested in observing.  As rpc.etherd
  903. only sees packets recieved on the interface it is running on, ethertop
  904. will only monitor traffic on a given subnet.  rpc.etherd puts the
  905. interface it monitors in promiscuous mode, and you must be root to
  906. start it.  Placing the interface in promiscuous mode causes a perforance
  907. hit as all packets on the network are interpreted.
  908. X
  909. X.SH DISPLAY
  910. The first lines of the display give information about the types of packets
  911. present on the network during the sample time.  Usually, the
  912. information is given in per second units.  Across the top are the
  913. following statistics: bytes (total bytes per second), pkts (packets per
  914. second), bcst (broadcast packets per seconds), tcp (tcp packets per
  915. second), udp (udp packets per second), icmp (icmp packets per second),
  916. arp (arp packets per second), nd (network disk packets per second), oth
  917. X(other packets per second).  Below those statistics is data on packet
  918. sizes.  These lines show how many packets per second of a particular
  919. size of packet is being sent on the network.
  920. The two columns below the packet statistics show the top senders and
  921. top recievers of packets.  Note that there is no direct correlation
  922. between the two columns on a line per line basis.
  923. X.SH COMMANDS
  924. Like top(1), 
  925. X.B ethertop
  926. runs in CBREAK mode and interprets commands on the
  927. fly from the terminal.  The following keys are meaningful:
  928. X.TP
  929. X.B i
  930. This toggles the IP number to hostname mapping.  
  931. X.B ethertop
  932. maintains a
  933. cache of IP to hostname mappings.  Hostnames are added to the cache
  934. as they appear.  This prevents beating on NIS or your local nameserver.
  935. X.TP
  936. X.B l 
  937. Redraws the screen.
  938. X.TP
  939. X.B n
  940. This changes the the number of hosts displayed.  Prompts for a number
  941. between 0 and the number of available lines on the screen.
  942. X.TP
  943. X.B s
  944. Changes the number of seconds between display updates.  Prompts for a number
  945. greater than 2.  Any less than this and the rpc traffic usually becomes
  946. significantly greater than any other traffic being measured.
  947. X.TP
  948. X.B t 
  949. Statistics usually display on a per seconds basis.  This can be
  950. changed with the to reflect total accumulated averages since the start of the
  951. program rather than during each sample interval.
  952. X.TP
  953. X.B q
  954. Quit ethertop.
  955. X.SH OPTIONS
  956. X.TP 15
  957. X.BI \-s " seconds"
  958. Specifies the amount of time to between samples and display updates.
  959. The default value is 5 seconds.  The can be set within the program
  960. with the s command.
  961. X.TP
  962. X.B -t
  963. Specifies that the packet counts and byte counts are to be time averaged since
  964. the program began running.  This is good for looking at long term trends in
  965. network usage, rather than pinpointing a specific abuser.  This can be toggled
  966. within the program with the t command.
  967. X
  968. X.TP
  969. X.B -i
  970. Specifies that 
  971. X.B ethertop
  972. should not map IP numbers to hostnames in the
  973. display.  This can be toggled in the program with the i command.
  974. X.SH "SEE ALSO"
  975. rpc.etherd(8C) traffic(1C)
  976. X.SH BUGS
  977. Somewhere.  The handling for when the remote rpc hosts dies could be
  978. better.  I am implementing packet type and host filters. They will
  979. appear in the next release.  Please feel free to send me bugs, comments,
  980. and suggestions.  This program needed to be written. Lets make it better.
  981. X.SH AUTHOR
  982. Guy Cardwell, Office of Academic Computing
  983. X
  984. University of California, Irvine
  985. X
  986. gcardwel@uci.edu.
  987. X
  988. END_OF_FILE
  989. if test 4091 -ne `wc -c <'ethertop.man'`; then
  990.     echo shar: \"'ethertop.man'\" unpacked with wrong size!
  991. fi
  992. # end of 'ethertop.man'
  993. fi
  994. if test -f 'hostname.c' -a "${1}" != "-c" ; then 
  995.   echo shar: Will not clobber existing file \"'hostname.c'\"
  996. else
  997. echo shar: Extracting \"'hostname.c'\" \(1850 characters\)
  998. sed "s/^X//" >'hostname.c' <<'END_OF_FILE'
  999. X/*
  1000. X * Copyright (c) 1991 Regents of the University of California.
  1001. X * All rights reserved.
  1002. X *
  1003. X * Redistribution and use in source and binary forms are permitted
  1004. X * provided that the above copyright notice and this paragraph are
  1005. X * duplicated in all such forms and that any documentation,
  1006. X * advertising materials, and other materials related to such
  1007. X * distribution and use acknowledge that the software was developed
  1008. X * by the University of California, Irvine.  The name of the
  1009. X * University may not be used to endorse or promote products derived
  1010. X * from this software without specific prior written permission.
  1011. X * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  1012. X * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  1013. X * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  1014. X */
  1015. X#include <stdio.h>
  1016. X#include <sys/types.h>
  1017. X#include <sys/socket.h>
  1018. X#include <netdb.h>
  1019. X#include <string.h>
  1020. X#include "ethertop.h"
  1021. X
  1022. X
  1023. static host_ip_ent *hash_table[H2IP_HASH_SIZE];
  1024. X
  1025. void init_gethostnamebyip()
  1026. X{
  1027. X  register int i;
  1028. X  for(i=0; i<H2IP_HASH_SIZE; i++)
  1029. X    hash_table[i]=NULL;
  1030. X}
  1031. X
  1032. X
  1033. char *gethostnamebyip(h_addr)
  1034. X     int h_addr;
  1035. X{
  1036. X  register host_ip_ent *ptr;
  1037. X  struct hostent *host;
  1038. X  host_ip_ent *temp;
  1039. X  unsigned int index;
  1040. X  if (displayip)
  1041. X    {
  1042. X      return(inet_ntoa(&h_addr));
  1043. X    }
  1044. X  index=((unsigned int)h_addr & H2IP_HASH_MASK);
  1045. X
  1046. X  for (ptr=hash_table[index] ; ptr!=NULL; ptr=ptr->h_nxt )
  1047. X    {
  1048. X      if (ptr->h_addr==h_addr)
  1049. X    {
  1050. X      return(ptr->h_name);
  1051. X    }
  1052. X    }
  1053. X  temp=hash_table[index];
  1054. X  ptr=hash_table[index]=(host_ip_ent *)malloc(sizeof(host_ip_ent));
  1055. X  ptr->h_nxt=temp;
  1056. X  ptr->h_addr=h_addr;
  1057. X  if ((host=gethostbyaddr(&h_addr,sizeof(int),AF_INET))!=NULL)
  1058. X    {
  1059. X      ptr->h_name=strdup(host->h_name);
  1060. X    }
  1061. X  else
  1062. X    {
  1063. X      ptr->h_name=strdup(inet_ntoa(&h_addr));
  1064. X    }
  1065. X  return(ptr->h_name);
  1066. X}
  1067. X
  1068. X
  1069. X
  1070. X  
  1071. X  
  1072. X
  1073. X
  1074. X
  1075. X
  1076. END_OF_FILE
  1077. if test 1850 -ne `wc -c <'hostname.c'`; then
  1078.     echo shar: \"'hostname.c'\" unpacked with wrong size!
  1079. fi
  1080. # end of 'hostname.c'
  1081. fi
  1082. if test -f 'patchlevel.h' -a "${1}" != "-c" ; then 
  1083.   echo shar: Will not clobber existing file \"'patchlevel.h'\"
  1084. else
  1085. echo shar: Extracting \"'patchlevel.h'\" \(21 characters\)
  1086. sed "s/^X//" >'patchlevel.h' <<'END_OF_FILE'
  1087. X#define PATCHLEVEL 1
  1088. END_OF_FILE
  1089. if test 21 -ne `wc -c <'patchlevel.h'`; then
  1090.     echo shar: \"'patchlevel.h'\" unpacked with wrong size!
  1091. fi
  1092. # end of 'patchlevel.h'
  1093. fi
  1094. if test -f 'screen.c' -a "${1}" != "-c" ; then 
  1095.   echo shar: Will not clobber existing file \"'screen.c'\"
  1096. else
  1097. echo shar: Extracting \"'screen.c'\" \(819 characters\)
  1098. sed "s/^X//" >'screen.c' <<'END_OF_FILE'
  1099. X/*
  1100. X * Copyright (c) 1991 Regents of the University of California.
  1101. X * All rights reserved.
  1102. X *
  1103. X * Redistribution and use in source and binary forms are permitted
  1104. X * provided that the above copyright notice and this paragraph are
  1105. X * duplicated in all such forms and that any documentation,
  1106. X * advertising materials, and other materials related to such
  1107. X * distribution and use acknowledge that the software was developed
  1108. X * by the University of California, Irvine.  The name of the
  1109. X * University may not be used to endorse or promote products derived
  1110. X * from this software without specific prior written permission.
  1111. X * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  1112. X * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  1113. X * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  1114. X */
  1115. END_OF_FILE
  1116. if test 819 -ne `wc -c <'screen.c'`; then
  1117.     echo shar: \"'screen.c'\" unpacked with wrong size!
  1118. fi
  1119. # end of 'screen.c'
  1120. fi
  1121. if test -f 'sort.c' -a "${1}" != "-c" ; then 
  1122.   echo shar: Will not clobber existing file \"'sort.c'\"
  1123. else
  1124. echo shar: Extracting \"'sort.c'\" \(3393 characters\)
  1125. sed "s/^X//" >'sort.c' <<'END_OF_FILE'
  1126. X/*
  1127. X * Copyright (c) 1991 Regents of the University of California.
  1128. X * All rights reserved.
  1129. X *
  1130. X * Redistribution and use in source and binary forms are permitted
  1131. X * provided that the above copyright notice and this paragraph are
  1132. X * duplicated in all such forms and that any documentation,
  1133. X * advertising materials, and other materials related to such
  1134. X * distribution and use acknowledge that the software was developed
  1135. X * by the University of California, Irvine.  The name of the
  1136. X * University may not be used to endorse or promote products derived
  1137. X * from this software without specific prior written permission.
  1138. X * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  1139. X * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  1140. X * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  1141. X */
  1142. X#include <stdio.h>
  1143. X#include "ethertop.h"
  1144. X#include "buffer.h"
  1145. X
  1146. X#define subtract(x,y) ((x)>(y) ? (x)-(y) : (y)-(x))
  1147. X
  1148. void subtract_etherstat(new,old,diff)
  1149. struct etherstat *new, *old;
  1150. etherfloatstat *diff;
  1151. X{
  1152. X  register unsigned int x;
  1153. X  float difftime;
  1154. X  difftime=(float) subtract(new->e_time.tv_seconds,old->e_time.tv_seconds)
  1155. X    + (subtract((float) new->e_time.tv_useconds , (float) old->e_time.tv_useconds)) / 1000000.00;
  1156. X  diff->e_time=difftime;
  1157. X  diff->e_bytes  =subtract(new->e_bytes,old->e_bytes)/difftime;
  1158. X  diff->e_packets=subtract(new->e_packets,old->e_packets)/difftime;
  1159. X  diff->e_bcast  =subtract(new->e_bcast,old->e_bcast)/difftime;
  1160. X  for (x=0; x<NPROTOS; x++)
  1161. X    {
  1162. X      diff->e_proto[x]=subtract(new->e_proto[x],old->e_proto[x])/difftime;
  1163. X    }
  1164. X  for (x=0; x<NBUCKETS; x++)
  1165. X    {
  1166. X      diff->e_size[x]=subtract(new->e_size[x],old->e_size[x])/difftime;
  1167. X    }
  1168. X}
  1169. X
  1170. X
  1171. X
  1172. X
  1173. int size_compare(a,b)
  1174. etherfloat_node **a,**b;
  1175. X{
  1176. X  if ((*b)->h_cnt < (*a)->h_cnt)
  1177. X    return -1;
  1178. X  if((*b)->h_cnt > (*a)->h_cnt)
  1179. X    return 1;
  1180. X  return 0;
  1181. X}
  1182. X
  1183. X
  1184. void subtract_and_sort_etheraddrs(new, old, buf)
  1185. X     struct etheraddrs *new,*old;
  1186. X     buffer *buf;
  1187. X{
  1188. X  register unsigned int i;
  1189. X  register float difftime;
  1190. X  etherhmem_node *newptr, *oldptr;
  1191. X  etherfloat_node *diffptr;
  1192. X  difftime=(float) subtract(new->e_time.tv_seconds,old->e_time.tv_seconds)
  1193. X    + (subtract((float) new->e_time.tv_useconds , (float) old->e_time.tv_useconds)) / 1000000.00;
  1194. X
  1195. X  for (i=0; i<HASHSIZE; i++)
  1196. X    {
  1197. X      newptr=new->e_addrs[i];
  1198. X      oldptr=old->e_addrs[i];
  1199. X      while(newptr!=NULL) /* not a valid record */
  1200. X    {
  1201. X      while (oldptr!=NULL &&  /* old record is there */
  1202. X         oldptr->h_addr!=newptr->h_addr) /* but record has been inserted */
  1203. X        {
  1204. X          oldptr=oldptr->h_nxt; /* jump to next old address until you reach end */
  1205. X                                /* or addresses match */
  1206. X        }
  1207. X      if (oldptr==NULL)  /* old record does not exist */
  1208. X        {
  1209. X          diffptr=(etherfloat_node *)malloc(sizeof(etherfloat_node));
  1210. X          diffptr->h_addr=newptr->h_addr;
  1211. X          diffptr->h_cnt=(float)(newptr->h_cnt) / difftime;
  1212. X          add_buffer(buf,diffptr);
  1213. X        }
  1214. X      else /* old record existed */
  1215. X        { 
  1216. X          if (newptr->h_cnt!=oldptr->h_cnt) /* count different */
  1217. X        {
  1218. X          diffptr=(etherfloat_node *)malloc(sizeof(etherfloat_node));
  1219. X          diffptr->h_addr=newptr->h_addr;
  1220. X          diffptr->h_cnt=(float) (subtract(newptr->h_cnt,oldptr->h_cnt)/difftime);
  1221. X          add_buffer(buf,diffptr);
  1222. X        }
  1223. X          oldptr=oldptr->h_nxt;
  1224. X        }
  1225. X      newptr=newptr->h_nxt;
  1226. X    }
  1227. X    }
  1228. X  qsort( (char *) buf->p, buf->end, sizeof(void *), size_compare);
  1229. X}
  1230. X
  1231. X
  1232. END_OF_FILE
  1233. if test 3393 -ne `wc -c <'sort.c'`; then
  1234.     echo shar: \"'sort.c'\" unpacked with wrong size!
  1235. fi
  1236. # end of 'sort.c'
  1237. fi
  1238. if test -f 'sort.h' -a "${1}" != "-c" ; then 
  1239.   echo shar: Will not clobber existing file \"'sort.h'\"
  1240. else
  1241. echo shar: Extracting \"'sort.h'\" \(884 characters\)
  1242. sed "s/^X//" >'sort.h' <<'END_OF_FILE'
  1243. X/*
  1244. X * Copyright (c) 1991 Regents of the University of California.
  1245. X * All rights reserved.
  1246. X *
  1247. X * Redistribution and use in source and binary forms are permitted
  1248. X * provided that the above copyright notice and this paragraph are
  1249. X * duplicated in all such forms and that any documentation,
  1250. X * advertising materials, and other materials related to such
  1251. X * distribution and use acknowledge that the software was developed
  1252. X * by the University of California, Irvine.  The name of the
  1253. X * University may not be used to endorse or promote products derived
  1254. X * from this software without specific prior written permission.
  1255. X * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  1256. X * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  1257. X * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  1258. X */
  1259. X
  1260. void subtract_and_sort_etheraddrs();
  1261. void subtract_etherstat();
  1262. END_OF_FILE
  1263. if test 884 -ne `wc -c <'sort.h'`; then
  1264.     echo shar: \"'sort.h'\" unpacked with wrong size!
  1265. fi
  1266. # end of 'sort.h'
  1267. fi
  1268. echo shar: End of archive 1 \(of 1\).
  1269. cp /dev/null ark1isdone
  1270. MISSING=""
  1271. for I in 1 ; do
  1272.     if test ! -f ark${I}isdone ; then
  1273.     MISSING="${MISSING} ${I}"
  1274.     fi
  1275. done
  1276. if test "${MISSING}" = "" ; then
  1277.     echo You have the archive.
  1278.     rm -f ark[1-9]isdone
  1279. else
  1280.     echo You still need to unpack the following archives:
  1281.     echo "        " ${MISSING}
  1282. fi
  1283. ##  End of shell archive.
  1284. exit 0
  1285.